package com.base.myproject.client.HR.setting;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.user.client.ui.Widget;

public class HR_Attendance_Exception_Setting extends BaseJDBCPanel{
	
	public HR_Attendance_Exception_Setting(){
		init();
	}
	
	public void init(){
		add(initWeigetx());
		registerMainStore(store);
		registerStore(store);
		setdefault();
	}
	
	public void complete(){
		super.complete();
	}
	
	private Widget initWeigetx(){
		VerticalPanel vpanel = new VerticalPanel();
		vpanel.add(createGrid());
		return vpanel;
		
	}
	private void setdefault() {
		store.addDefault("type", "hr_attException");
		
	}

	BaseStore<BusiObject> store = null;
	public BaseStore<BusiObject> getStore(){
		if(store==null) {
			createStore();
		}
		return store;
	}
	public BaseStore<BusiObject> createStore(){
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);
		type.addField("type");
		type.getField("type").setType(String.class);
		type.addField("mark");
		type.getField("mark").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("dictionary");
		info.setKeyname(new String[] { "icode"});
		info.setSql("select * from dictionary where type='hr_attException'");
		store = new BaseStore<BusiObject>(type, info);
		  
		 return store;
	}
	

	BaseGridPanel grid=null;
	public BaseGridPanel createGrid(){
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
	
		ColumnConfig C2 = new ColumnConfig("code", "编码", 80);
		C2.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("name", "异常状态", 80);
		C3.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("mark", "说明", 80);
		C4.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C4);
	
		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGridPanel(getStore(), cm,true,true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		grid.getBg().setSelectionModel(cbs);
		grid.setHeight(400);
		grid.setWidth(300);
		return grid ;
	}

}
